Skip to content

Add development reload for docket worker - #634

Merged
chrisguidry merged 3 commits into
chrisguidry:mainfrom
omikader:codex/worker-reload
Nov 25, 2026
Merged

chrisguidry merged 3 commits into
chrisguidry:mainfrom
omikader:codex/worker-reload

Conversation

@omikader

Copy link
Copy Markdown
Contributor

Closes #565.

Summary

  • Add docket worker --reload for local development. It watches Python files under the current directory and starts a fresh worker process after changes.
  • Preserve worker options and logging across restarts. Reject --reload with --until-finished.
  • Document the flag and test the installed CLI, including re-importing edited task code, preserving JSON logging, and shutting down cleanly.

Verification

  • Redis 8.10 CLI suite with CI coverage settings: 107 passed, 100% branch coverage.
  • In-memory core suite: 100% coverage after retrying two instrumentation tests.
  • Ruff, Pyright, codespell, and workspace hooks passed. Rust hooks were skipped locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:35:26.451537Z a084336 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

read-the-docs-community Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 docket | 🛠️ Build #36147644 | 📁 Comparing b51b776 against latest (90bf414)

  🔍 Preview build  

2 files changed
± index.html
± getting-started/index.html

@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
1338 1 1337 8
View the top 1 failed test(s) by shortest run time
tests/cli/test_worker.py::test_reload_rejects_until_finished
Stack Traces | 0.789s run time
async def test_reload_rejects_until_finished() -> None:
        result = await run_cli("worker", "--reload", "--until-finished")
    
        assert result.exit_code == 2
>       assert "--reload cannot be used with --until-finished" in result.output
E       assert '--reload cannot be used with --until-finished' in "\x1b[1;33mUsage: \x1b[0m\x1b[1mpython \x1b[0m\x1b[1;32m-m\x1b[0m\x1b[1m docket worker [OPTIONS]\x1b[0m\n\x1b[2mTry \x...   \x1b[31m│\x1b[0m\n\x1b[31m╰──────────────────────────────────────────────────────────────────────────────╯\x1b[0m\n"
E        +  where "\x1b[1;33mUsage: \x1b[0m\x1b[1mpython \x1b[0m\x1b[1;32m-m\x1b[0m\x1b[1m docket worker [OPTIONS]\x1b[0m\n\x1b[2mTry \x...   \x1b[31m│\x1b[0m\n\x1b[31m╰──────────────────────────────────────────────────────────────────────────────╯\x1b[0m\n" = CliResult(exit_code=2, stdout='', stderr="\x1b[1;33mUsage: \x1b[0m\x1b[1mpython \x1b[0m\x1b[1;32m-m\x1b[0m\x1b[1m dock...  \x1b[31m│\x1b[0m\n\x1b[31m╰──────────────────────────────────────────────────────────────────────────────╯\x1b[0m\n").output

tests/cli/test_worker.py:129: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0843360ba

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

) -> None:
set_logging_level(logging_level)
set_logging_format(logging_format)
asyncio.run(worker())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bypass stale bytecode before importing reloaded tasks

With --reload, if a task module is edited to the same byte length within the same timestamp second as the bytecode currently in __pycache__ (for example, a fast before→edited rename), Python can accept that timestamp-based .pyc because it validates only the source's integer mtime and size. The watcher fires, but this invocation then imports the old bytecode and no event remains to retry, so users see the old task implementation; test_worker.py:172-177 masks this case by forcing the mtime two seconds forward. Ensure reload children bypass or remove affected bytecode before importing the task collection.

Useful? React with 👍 / 👎.

logging_level: LogLevel,
logging_format: LogFormat,
) -> None:
run_process(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the worker's graceful drain during reloads

When --reload is used while an in-flight task takes more than five seconds, this call inherits watchfiles' 5-second sigint_timeout and then force-kills the child. Worker._worker_loop intentionally waits for active tasks in worker.py:887-902, so a save or Ctrl+C cuts that drain short, leaves the stream message pending until redelivery, and contradicts the documented CLI graceful-shutdown behavior; expose or configure an adequate drain timeout rather than relying on the reloader default.

AGENTS.md reference: AGENTS.md:L97-L103

Useful? React with 👍 / 👎.

@chrisguidry
chrisguidry merged commit 66f6036 into chrisguidry:main Nov 25, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: auto-reload for docket worker in local development?

3 participants